package first;


import java.io.*;

public class EditBean {
    private String  username;
    private String  password;
    private String  postbox;
    private String  fname;
    private String  sname;
    private String  department;
    private String  object;
    private  String url;

    public EditBean() {}

    public String getUsername(){
        return username;
    }

    public void setUsername(String username){
        this.username=username;
    }

    public String getPassword(){
        return password;
    }

    public void setPassword(String password){
        this.password=password;
    }

    public String readFileContent(String username,String postbox,String fname,String sname,String department,String object) {
            BufferedReader br = null;
            String line = null;
            StringBuffer bufAll = new StringBuffer(); //保存修改过后的所有内容，不断增加         
            try {
                 br = new BufferedReader(new FileReader("Student.txt"));
                String[] massege;
                 while ((line = br.readLine()) != null) {
                     StringBuffer buf = new StringBuffer();
                     //修改内容核心代码
                     if (line.startsWith(username)) {
                         massege=line.split(",");
                       buf.append(username);
                       buf.append(",");
                       buf.append(massege[1]);
                       buf.append(",");
                       buf.append(postbox);
                       buf.append(",");
                       buf.append(fname);
                       buf.append(",");
                       buf.append(sname);
                       buf.append(",");
                       buf.append(department);
                       buf.append(",");
                       buf.append(object);
                       buf.append(",");
                       buf.append(massege[7]);
                       bufAll.append(buf);
                       bufAll.append("\r\n");
                     }
                     else {
                         bufAll.append(line);
                         bufAll.append("\r\n");
                     }

                 }
            } catch (Exception e) {
                 e.printStackTrace();
            } finally {
                if (br != null) {
                   try {
                       br.close();
                   } catch (IOException e) {
                       br = null;
                  }
              }
            }
            return bufAll.toString();
    }
            //写回文
    public void writeFile(String content) {
        BufferedWriter bw = null;
        try {
              bw = new BufferedWriter(new FileWriter("student.txt"));
              bw.write(content);
       } catch (Exception e) {
                e.printStackTrace();
       } finally {
           if (bw != null) {
              try {
                 bw.close();
              } catch (IOException e) {
                     bw = null;
               }
          }
       }
   }


}
